﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MG_POS_PC.Util;
using System.Data;
using System.Data.SqlClient;

namespace MG_POS_PC.DAL.Setting
{
    /// <summary>
    /// 数据访问类:t_pos_setting
    /// </summary>
    public partial class t_pos_setting
    {
        public t_pos_setting()
        { }
        #region  BasicMethod


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(MG_POS_PC.Model.Setting.t_pos_setting model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_pos_setting(");
            strSql.Append("ps_station,ps_open_time,ps_close_time,ps_tare_rate,ps_fc_max,create_datetime,update_datetime,ps_weight_unit,ps_store_no,ps_price_digits,ps_currency_sign,ps_out_of_paper,ps_calc_weight,ps_calendar_type,ps_norm_upce,ps_network_onoff,ps_show_desc,ps_dvr,ps_zero_baln,ps_zero_price,ps_fs_tax_rule,ps_prctag_printer,ps_rounding,ps_print_service,ps_sig_host,ps_sig_local,ps_sig_min,ps_receipt_pnt)");
            strSql.Append(" values (");
            strSql.Append("@ps_station,@ps_open_time,@ps_close_time,@ps_tare_rate,@ps_fc_max,@create_datetime,@update_datetime,@ps_weight_unit,@ps_store_no,@ps_price_digits,@ps_currency_sign,@ps_out_of_paper,@ps_calc_weight,@ps_calendar_type,@ps_norm_upce,@ps_network_onoff,@ps_show_desc,@ps_dvr,@ps_zero_baln,@ps_zero_price,@ps_fs_tax_rule,@ps_prctag_printer,@ps_rounding,@ps_print_service,@ps_sig_host,@ps_sig_local,@ps_sig_min,@ps_receipt_pnt)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@ps_station", SqlDbType.Decimal,5),
					new SqlParameter("@ps_open_time", SqlDbType.NVarChar,50),
					new SqlParameter("@ps_close_time", SqlDbType.NVarChar,50),
					new SqlParameter("@ps_tare_rate", SqlDbType.Decimal,5),
					new SqlParameter("@ps_fc_max", SqlDbType.Int,4),
					new SqlParameter("@create_datetime", SqlDbType.NVarChar,50),
					new SqlParameter("@update_datetime", SqlDbType.NVarChar,50),
					new SqlParameter("@ps_weight_unit", SqlDbType.NVarChar,2),
					new SqlParameter("@ps_store_no", SqlDbType.Int,4),
					new SqlParameter("@ps_price_digits", SqlDbType.Decimal,5),
					new SqlParameter("@ps_currency_sign", SqlDbType.NVarChar,50),
					new SqlParameter("@ps_out_of_paper", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_calc_weight", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_calendar_type", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_norm_upce", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_network_onoff", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_show_desc", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_dvr", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_zero_baln", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_zero_price", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_fs_tax_rule", SqlDbType.Decimal,5),
					new SqlParameter("@ps_prctag_printer", SqlDbType.Int,4),
					new SqlParameter("@ps_rounding", SqlDbType.Int,4),
					new SqlParameter("@ps_print_service", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_sig_host", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_sig_local", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_sig_min", SqlDbType.Decimal,5),
					new SqlParameter("@ps_receipt_pnt", SqlDbType.Int,4)};
            parameters[0].Value = model.ps_station;
            parameters[1].Value = model.ps_open_time;
            parameters[2].Value = model.ps_close_time;
            parameters[3].Value = model.ps_tare_rate;
            parameters[4].Value = model.ps_fc_max;
            parameters[5].Value = model.create_datetime;
            parameters[6].Value = model.update_datetime;
            parameters[7].Value = model.ps_weight_unit;
            parameters[8].Value = model.ps_store_no;
            parameters[9].Value = model.ps_price_digits;
            parameters[10].Value = model.ps_currency_sign;
            parameters[11].Value = model.ps_out_of_paper;
            parameters[12].Value = model.ps_calc_weight;
            parameters[13].Value = model.ps_calendar_type;
            parameters[14].Value = model.ps_norm_upce;
            parameters[15].Value = model.ps_network_onoff;
            parameters[16].Value = model.ps_show_desc;
            parameters[17].Value = model.ps_dvr;
            parameters[18].Value = model.ps_zero_baln;
            parameters[19].Value = model.ps_zero_price;
            parameters[20].Value = model.ps_fs_tax_rule;
            parameters[21].Value = model.ps_prctag_printer;
            parameters[22].Value = model.ps_rounding;
            parameters[23].Value = model.ps_print_service;
            parameters[24].Value = model.ps_sig_host;
            parameters[25].Value = model.ps_sig_local;
            parameters[26].Value = model.ps_sig_min;
            parameters[27].Value = model.ps_receipt_pnt;

            object obj = DBHelper.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(MG_POS_PC.Model.Setting.t_pos_setting model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_pos_setting set ");
            strSql.Append("ps_station=@ps_station,");
            strSql.Append("ps_open_time=@ps_open_time,");
            strSql.Append("ps_close_time=@ps_close_time,");
            strSql.Append("ps_tare_rate=@ps_tare_rate,");
            strSql.Append("ps_fc_max=@ps_fc_max,");
            strSql.Append("create_datetime=@create_datetime,");
            strSql.Append("update_datetime=@update_datetime,");
            strSql.Append("ps_weight_unit=@ps_weight_unit,");
            strSql.Append("ps_store_no=@ps_store_no,");
            strSql.Append("ps_price_digits=@ps_price_digits,");
            strSql.Append("ps_currency_sign=@ps_currency_sign,");
            strSql.Append("ps_out_of_paper=@ps_out_of_paper,");
            strSql.Append("ps_calc_weight=@ps_calc_weight,");
            strSql.Append("ps_calendar_type=@ps_calendar_type,");
            strSql.Append("ps_norm_upce=@ps_norm_upce,");
            strSql.Append("ps_network_onoff=@ps_network_onoff,");
            strSql.Append("ps_show_desc=@ps_show_desc,");
            strSql.Append("ps_dvr=@ps_dvr,");
            strSql.Append("ps_zero_baln=@ps_zero_baln,");
            strSql.Append("ps_zero_price=@ps_zero_price,");
            strSql.Append("ps_fs_tax_rule=@ps_fs_tax_rule,");
            strSql.Append("ps_prctag_printer=@ps_prctag_printer,");
            strSql.Append("ps_rounding=@ps_rounding,");
            strSql.Append("ps_print_service=@ps_print_service,");
            strSql.Append("ps_sig_host=@ps_sig_host,");
            strSql.Append("ps_sig_local=@ps_sig_local,");
            strSql.Append("ps_sig_min=@ps_sig_min,");
            strSql.Append("ps_receipt_pnt=@ps_receipt_pnt");
            strSql.Append(" where ps_id=@ps_id");
            SqlParameter[] parameters = {
					new SqlParameter("@ps_station", SqlDbType.Decimal,5),
					new SqlParameter("@ps_open_time", SqlDbType.NVarChar,50),
					new SqlParameter("@ps_close_time", SqlDbType.NVarChar,50),
					new SqlParameter("@ps_tare_rate", SqlDbType.Decimal,5),
					new SqlParameter("@ps_fc_max", SqlDbType.Int,4),
					new SqlParameter("@create_datetime", SqlDbType.NVarChar,50),
					new SqlParameter("@update_datetime", SqlDbType.NVarChar,50),
					new SqlParameter("@ps_weight_unit", SqlDbType.NVarChar,2),
					new SqlParameter("@ps_store_no", SqlDbType.Int,4),
					new SqlParameter("@ps_price_digits", SqlDbType.Decimal,5),
					new SqlParameter("@ps_currency_sign", SqlDbType.NVarChar,50),
					new SqlParameter("@ps_out_of_paper", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_calc_weight", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_calendar_type", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_norm_upce", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_network_onoff", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_show_desc", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_dvr", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_zero_baln", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_zero_price", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_fs_tax_rule", SqlDbType.Decimal,5),
					new SqlParameter("@ps_prctag_printer", SqlDbType.Int,4),
					new SqlParameter("@ps_rounding", SqlDbType.Int,4),
					new SqlParameter("@ps_print_service", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_sig_host", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_sig_local", SqlDbType.NVarChar,1),
					new SqlParameter("@ps_sig_min", SqlDbType.Decimal,5),
					new SqlParameter("@ps_receipt_pnt", SqlDbType.Int,4),
					new SqlParameter("@ps_id", SqlDbType.Int,4)};
            parameters[0].Value = model.ps_station;
            parameters[1].Value = model.ps_open_time;
            parameters[2].Value = model.ps_close_time;
            parameters[3].Value = model.ps_tare_rate;
            parameters[4].Value = model.ps_fc_max;
            parameters[5].Value = model.create_datetime;
            parameters[6].Value = model.update_datetime;
            parameters[7].Value = model.ps_weight_unit;
            parameters[8].Value = model.ps_store_no;
            parameters[9].Value = model.ps_price_digits;
            parameters[10].Value = model.ps_currency_sign;
            parameters[11].Value = model.ps_out_of_paper;
            parameters[12].Value = model.ps_calc_weight;
            parameters[13].Value = model.ps_calendar_type;
            parameters[14].Value = model.ps_norm_upce;
            parameters[15].Value = model.ps_network_onoff;
            parameters[16].Value = model.ps_show_desc;
            parameters[17].Value = model.ps_dvr;
            parameters[18].Value = model.ps_zero_baln;
            parameters[19].Value = model.ps_zero_price;
            parameters[20].Value = model.ps_fs_tax_rule;
            parameters[21].Value = model.ps_prctag_printer;
            parameters[22].Value = model.ps_rounding;
            parameters[23].Value = model.ps_print_service;
            parameters[24].Value = model.ps_sig_host;
            parameters[25].Value = model.ps_sig_local;
            parameters[26].Value = model.ps_sig_min;
            parameters[27].Value = model.ps_receipt_pnt;
            parameters[28].Value = model.ps_id;

            int rows = DBHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ps_id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_pos_setting ");
            strSql.Append(" where ps_id=@ps_id");
            SqlParameter[] parameters = {
					new SqlParameter("@ps_id", SqlDbType.Int,4)
			};
            parameters[0].Value = ps_id;

            int rows = DBHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string ps_idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_pos_setting ");
            strSql.Append(" where ps_id in (" + ps_idlist + ")  ");
            int rows = DBHelper.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public MG_POS_PC.Model.Setting.t_pos_setting GetModel(int ps_id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ps_id,ps_station,ps_open_time,ps_close_time,ps_tare_rate,ps_fc_max,create_datetime,update_datetime,ps_weight_unit,ps_store_no,ps_price_digits,ps_currency_sign,ps_out_of_paper,ps_calc_weight,ps_calendar_type,ps_norm_upce,ps_network_onoff,ps_show_desc,ps_dvr,ps_zero_baln,ps_zero_price,ps_fs_tax_rule,ps_prctag_printer,ps_rounding,ps_print_service,ps_sig_host,ps_sig_local,ps_sig_min,ps_receipt_pnt from t_pos_setting ");
            strSql.Append(" where ps_id=@ps_id");
            SqlParameter[] parameters = {
					new SqlParameter("@ps_id", SqlDbType.Int,4)
			};
            parameters[0].Value = ps_id;

            MG_POS_PC.Model.Setting.t_pos_setting model = new MG_POS_PC.Model.Setting.t_pos_setting();
            DataSet ds = DBHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public MG_POS_PC.Model.Setting.t_pos_setting DataRowToModel(DataRow row)
        {
            MG_POS_PC.Model.Setting.t_pos_setting model = new MG_POS_PC.Model.Setting.t_pos_setting();
            if (row != null)
            {
                if (row["ps_id"] != null && row["ps_id"].ToString() != "")
                {
                    model.ps_id = int.Parse(row["ps_id"].ToString());
                }
                if (row["ps_station"] != null && row["ps_station"].ToString() != "")
                {
                    model.ps_station = int.Parse(row["ps_station"].ToString());
                }
                if (row["ps_open_time"] != null)
                {
                    model.ps_open_time = row["ps_open_time"].ToString();
                }
                if (row["ps_close_time"] != null)
                {
                    model.ps_close_time = row["ps_close_time"].ToString();
                }
                if (row["ps_tare_rate"] != null && row["ps_tare_rate"].ToString() != "")
                {
                    model.ps_tare_rate = double.Parse(row["ps_tare_rate"].ToString());
                }
                if (row["ps_fc_max"] != null && row["ps_fc_max"].ToString() != "")
                {
                    model.ps_fc_max = int.Parse(row["ps_fc_max"].ToString());
                }
                if (row["create_datetime"] != null)
                {
                    model.create_datetime = row["create_datetime"].ToString();
                }
                if (row["update_datetime"] != null)
                {
                    model.update_datetime = row["update_datetime"].ToString();
                }
                if (row["ps_weight_unit"] != null)
                {
                    model.ps_weight_unit = row["ps_weight_unit"].ToString();
                }
                if (row["ps_store_no"] != null && row["ps_store_no"].ToString() != "")
                {
                    model.ps_store_no = int.Parse(row["ps_store_no"].ToString());
                }
                if (row["ps_price_digits"] != null && row["ps_price_digits"].ToString() != "")
                {
                    model.ps_price_digits = int.Parse(row["ps_price_digits"].ToString());
                }
                if (row["ps_currency_sign"] != null)
                {
                    model.ps_currency_sign = row["ps_currency_sign"].ToString();
                }
                if (row["ps_out_of_paper"] != null)
                {
                    model.ps_out_of_paper = row["ps_out_of_paper"].ToString();
                }
                if (row["ps_calc_weight"] != null)
                {
                    model.ps_calc_weight = row["ps_calc_weight"].ToString();
                }
                if (row["ps_calendar_type"] != null)
                {
                    model.ps_calendar_type = row["ps_calendar_type"].ToString();
                }
                if (row["ps_norm_upce"] != null)
                {
                    model.ps_norm_upce = row["ps_norm_upce"].ToString();
                }
                if (row["ps_network_onoff"] != null)
                {
                    model.ps_network_onoff = row["ps_network_onoff"].ToString();
                }
                if (row["ps_show_desc"] != null)
                {
                    model.ps_show_desc = row["ps_show_desc"].ToString();
                }
                if (row["ps_dvr"] != null)
                {
                    model.ps_dvr = row["ps_dvr"].ToString();
                }
                if (row["ps_zero_baln"] != null)
                {
                    model.ps_zero_baln = row["ps_zero_baln"].ToString();
                }
                if (row["ps_zero_price"] != null)
                {
                    model.ps_zero_price = row["ps_zero_price"].ToString();
                }
                if (row["ps_fs_tax_rule"] != null && row["ps_fs_tax_rule"].ToString() != "")
                {
                    model.ps_fs_tax_rule = int.Parse(row["ps_fs_tax_rule"].ToString());
                }
                if (row["ps_prctag_printer"] != null && row["ps_prctag_printer"].ToString() != "")
                {
                    model.ps_prctag_printer = int.Parse(row["ps_prctag_printer"].ToString());
                }
                if (row["ps_rounding"] != null && row["ps_rounding"].ToString() != "")
                {
                    model.ps_rounding = int.Parse(row["ps_rounding"].ToString());
                }
                if (row["ps_print_service"] != null)
                {
                    model.ps_print_service = row["ps_print_service"].ToString();
                }
                if (row["ps_sig_host"] != null)
                {
                    model.ps_sig_host = row["ps_sig_host"].ToString();
                }
                if (row["ps_sig_local"] != null)
                {
                    model.ps_sig_local = row["ps_sig_local"].ToString();
                }
                if (row["ps_sig_min"] != null && row["ps_sig_min"].ToString() != "")
                {
                    model.ps_sig_min = double.Parse(row["ps_sig_min"].ToString());
                }
                if (row["ps_receipt_pnt"] != null && row["ps_receipt_pnt"].ToString() != "")
                {
                    model.ps_receipt_pnt = int.Parse(row["ps_receipt_pnt"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ps_id,ps_station,ps_open_time,ps_close_time,ps_tare_rate,ps_fc_max,create_datetime,update_datetime,ps_weight_unit,ps_store_no,ps_price_digits,ps_currency_sign,ps_out_of_paper,ps_calc_weight,ps_calendar_type,ps_norm_upce,ps_network_onoff,ps_show_desc,ps_dvr,ps_zero_baln,ps_zero_price,ps_fs_tax_rule,ps_prctag_printer,ps_rounding,ps_print_service,ps_sig_host,ps_sig_local,ps_sig_min,ps_receipt_pnt ");
            strSql.Append(" FROM t_pos_setting ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DBHelper.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" ps_id,ps_station,ps_open_time,ps_close_time,ps_tare_rate,ps_fc_max,create_datetime,update_datetime,ps_weight_unit,ps_store_no,ps_price_digits,ps_currency_sign,ps_out_of_paper,ps_calc_weight,ps_calendar_type,ps_norm_upce,ps_network_onoff,ps_show_desc,ps_dvr,ps_zero_baln,ps_zero_price,ps_fs_tax_rule,ps_prctag_printer,ps_rounding,ps_print_service,ps_sig_host,ps_sig_local,ps_sig_min,ps_receipt_pnt ");
            strSql.Append(" FROM t_pos_setting ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DBHelper.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM t_pos_setting ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DBHelper.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.ps_id desc");
            }
            strSql.Append(")AS Row, T.*  from t_pos_setting T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DBHelper.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "t_pos_setting";
            parameters[1].Value = "ps_id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}
